package com.w2cx.selenium.operate;

import com.w2cx.selenium.base.DriverBase;
import com.w2cx.selenium.page.MarkCategoryManagePage;
import org.openqa.selenium.WebElement;

import java.util.ArrayList;
import java.util.List;

public class MarkCategoryManageOperate {
    DriverBase driver;
    MarkCategoryManagePage mcmp;
    public MarkCategoryManageOperate(DriverBase driver){
        this.driver = driver;
        mcmp = new MarkCategoryManagePage(driver);
    }

    //点击“基础数据管理”菜单
    public void clickBaseDataManageMenu(){
        mcmp.click(mcmp.getBaseDataManageMenu());
    }


    //点击“标签分类管理”菜单
    public void clickMarkCategoryManageMenu(){
        mcmp.click(mcmp.getMarkCategoryManageMenu());
    }



    //点击“添加”按钮
    public void clickAddBtn(){
        mcmp.click(mcmp.getMarkCategoryAddBtn());
    }


    //输入“分类名称”
    public void inputCategoryName(String categoryName){
        mcmp.sendKeys(mcmp.getCategoryNameInput(),categoryName);
    }

    //输入“上级分类名称”
   /* public void inputHigherCategoryName(String higherCategoryName){
        mcmp.sendKeys(mcmp.getHigherCategoryInput(),higherCategoryName);
    }*/


    //点击"确定"按钮
    public void clickConfirmBtn(){
        mcmp.click(mcmp.getConfirmBtn());
    }

    //获得元素列表
    public List<WebElement> getMarkCategoryList(){
        return  mcmp.getMarkCategoryList();
    }




    //点击“删除”按钮
    public void clickDelBtn(String alreadyAddMarkCategoryName){
        //获取level0级别的分类列表
        ArrayList<WebElement> list = (ArrayList<WebElement>) mcmp.getMarkCategoryLevel0List();
        for (int i=0;i<list.size();i++){
            WebElement element = list.get(i);
            if(element.getText().contains(alreadyAddMarkCategoryName)){
                //System.out.println("已添加分类："+element.getText());
                //点击元素对应的删除按钮
                mcmp.click(mcmp.getMarkCategoryDelBtn(element));


                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                //点击删除对话框中的“确定”按钮
                mcmp.click(mcmp.getDelOkBtn());
                break;
            }
        }



    }


}
